#define _GNU_SOURCE
#include <pthread.h>
#include <unistd.h>
#include <stdio.h>

void *thread_func1(void *arg)
{   int i=0;
    while (i<10)
    {
        printf("thread1 is running : %d\n",gettid());
        sleep(1);
        i++;
    }
    printf("thread1 is exit\n");
    return NULL;
}

void *thread_func2(void *arg)
{   int i=0;
    while (i<5)
    {
        printf("thread2 is running : %d\n",gettid());
        sleep(1);
        i++;
    }
    printf("thread2 is exit\n");
    return NULL;
}

int main(int argc, char const *argv[])
{
    // 声明线程句柄
    pthread_t thread1 ,thread2;
    pthread_create(&thread1, NULL, thread_func1, NULL);
    pthread_create(&thread2, NULL, thread_func2, NULL);

   // 此时进程中有几个线程?   
      sleep(5);
      pthread_cancel(thread1);
      // 等待子线程结束
      pthread_join(thread1, NULL);
      pthread_join(thread2, NULL);
      printf("main thread exit\n");
    return 0;
}
